<template>
  <!-- 添加或修改项目基础信息管理对话框 -->
  <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" append-to-body width="80%">
    <el-form :model="form" :rules="rules" label-width="125px" ref="form">
      <el-tabs type="card" v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="用料明细" name="用料明细">
          <goods-sale-material-list :projectCode="form.code" ref="GoodsSaleMaterialListForm"></goods-sale-material-list>
        </el-tab-pane>
        <el-tab-pane label="报工记录" name="报工记录">
          <goods-saledo-gongxu-user-money-list :projectCode="form.code" ref="GoodsSaledoGongxuUserMoneyListForm"></goods-saledo-gongxu-user-money-list>
        </el-tab-pane>
      </el-tabs>
    </el-form>

    <div class="dialog-footer" slot="footer">
      <el-button @click="submitForm" type="primary">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { addAction, getAction, getById, updateAction } from '@/api/manage';

import GoodsSaleMaterialList from "../../goodsSaleMaterial/GoodsSaleMaterialList";
import GoodsSaledoGongxuUserMoneyList from "../../goodsSaledoGongxuUserMoney/GoodsSaledoGongxuUserMoneyList";

export default {
  name: "FeeMoneyFormList",
  dicts: ['goods_customer', 'company', 'yes_no', 'yewu_type','invoice_back_status'],
  components: {
    GoodsSaleMaterialList,
    GoodsSaledoGongxuUserMoneyList
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      activeName: "用料明细",
      // 弹出层标题
      title: "费用金额",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      salesmanList: [],
      // 表单校验
      rules: {
        projectId: [{required: true,message: "请选择所属项目",trigger: "blur"}],
        code: [{required: true,message: "订单编号不能为空",trigger: "blur"},],
        year: [{required: true,message: "所属年度不能为空",trigger: "blur"}],
        name: [{required: true,message: "订单名称不能为空",trigger: "blur"}],
        salesmanId: [{required: true,message: "请选择业务员",trigger: "blur"}],
        customId: [{required: true,message: "买方不能为空",trigger: "blur"}],
        companyId: [{required: true,message: "项目单位不能为空",trigger: "blur"}],
        goodsType: [{required: true,message: "请选择订单类别",trigger: "blur"}],
        createName: [{required: true,message: "制单人不能为空",trigger: "blur"}],
        area: [{required: true,message: "地区不能为空",trigger: "blur"}],
        contractDate: [{required: true,message: "合同签订日期不能为空",trigger: "blur"}],
      },
      url: {
        getById: '/projectBaseInfo/projectBaseInfo/',
        add: '/projectBaseInfo/projectBaseInfo/add',
        edit: '/projectBaseInfo/projectBaseInfo/edit',
        salesmanList: '/system/role/authUser/allocatedList',
      },
      type2: "2",
      type3: "3",
      // 部门树选项
      deptOptions: [],
    };
  },
  created() {
    this.getTreeselect();
    this.getSalesmanList();
  },
  methods: {
    selectDept(e) {
      let that = this;
      that.$set(that.form, "deptName", e.label);
    },
    /** 查询部门下拉树结构 */
    getTreeselect() {
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    handleUpdateDetail(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "完善项1目信息";
      });
    },
    updateAuditMoney(value) {
      this.$set(this.form, "auditMoney", value);
    },
    selectCustomerForPrj(value) {
      let that = this;
      that.$nextTick(() => {
        let arr = that.$refs.myselectCustomerForPrj;
        for (let i = 0; i < arr.length; i++) {
          if (arr[i].currentValue == value) {
            that.form.customName = arr[i].label;
          }
        }
      })
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        name: null,
        master: null,
        customId: null,
        customName: null,
        companyName: null,
        contractDate: null,
        contractMoney: null,
        auditMoney: null,
        checkDate: null,
        checkState: null,
        fundCallback: null,
        information: null,
        remainMoney: null,
        feeMoney: null,
        taxRemain: null
      };
      this.resetForm("form");
    },
    handleClick(tab, event) {
        console.log(tab, event);
      },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加项目基础信息管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getById(this.url.getById, id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改订单基础信息管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateAction(this.url.edit, this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.$emit('ok');
            });
          } else {
            addAction(this.url.add, this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.$emit('ok');
            });
          }
        }
      });
    },
    sheowFeeMoney(row) {
      // 实现显示费用金额详情的逻辑
      console.log('显示费用金额详情:', row);
      // 这里可以添加具体的显示逻辑，例如打开一个弹窗展示详情
      this.form = { ...row }; // 将传入的 row 数据赋值给 form
      this.open = true; // 打开弹窗
    },
    getSalesmanList() {
      getAction(this.url.salesmanList, {
        "roleId": "e1c2bca31b7944e98f79008c726cf7e8"
      }).then(response => {
        this.salesmanList = response.rows;
      });
    }

  }
};
</script>
